home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / SERIAL.TST / SETSERL.C < prev    next >
C/C++ Source or Header  |  1996-01-07  |  4KB  |  110 lines

  1. /* ============ */
  2. /* setserl.c    */
  3. /* ============ */
  4. #include <io.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <miscdefs.h>
  8. #include <serldefs.h>
  9.  
  10. #define    ACT(X)    #X
  11.  
  12. #define    CLAMP(Var, Lo, Hi)    __min(Hi, __max(Lo, Var))
  13.  
  14. #define    NEED_CELL_EXPECT(LO, HI) \
  15.     "Enter Minimum Cell Expectation ["ACT(LO)"-"ACT(HI)"]: "
  16.  
  17. #define    NEED_DATA_SET_SIZE(LO, HI) \
  18.     "Enter Size of Data Set ["ACT(LO)"-"ACT(HI)"]: "
  19.  
  20. #define    REPORT_USER_INT_ENTRY(Entry, Label)        \
  21.     {                            \
  22.     fflush(NULL); printf("\n");            \
  23.     printf("\tNumber Entered:  %.f", (double)Entry);\
  24.     printf(" (%s)\n", Label);            \
  25.     }
  26. #define    SHOW_INT_VALUE_USED(Entered, Used)             \
  27.     printf("\tTest Value Used: %.f%s\n", (double)Used,    \
  28.     ((double)Entered == (double)Used) ? "" : " (Clamped)")
  29.  
  30. /* ==================================================================== */
  31. /* SetSerialControls - Puts Run Controls in SerialData structure    */
  32. /* ==================================================================== */
  33. void
  34. SetSerialControls(SERIAL_DATA_STRU  *SerialData)
  35. {
  36.     int     NewlineCh;
  37.     int     UserIntEntry;
  38.     long    UserLongEntry;
  39.  
  40.     NewlineCh = _isatty(_fileno(stdin)) ? '\r' : '\n';
  41.  
  42.     fflush(NULL);fprintf(stderr, "%c", NewlineCh);
  43.     /* ------------------------------------------ */
  44.     /* Request Number Integers in Serial Data Set */
  45.     /* ------------------------------------------ */
  46.     GetInt(NEED_DATA_SET_SIZE(MIN_SET_SIZE, MAX_SET_SIZE), &UserIntEntry);
  47.  
  48.     REPORT_USER_INT_ENTRY(UserIntEntry, "Size of Data Set");
  49.  
  50.     SerialData->SetSize = CLAMP(UserIntEntry, MIN_SET_SIZE, MAX_SET_SIZE);
  51.  
  52.     SHOW_INT_VALUE_USED(UserIntEntry, SerialData->SetSize);
  53.  
  54.     fflush(NULL);fprintf(stderr, "%c", NewlineCh);
  55.     /* ------------------------------ */
  56.     /* Calculate Number of Categories */
  57.     /* ------------------------------ */
  58.     SerialData->NumCategories = SQR(SerialData->SetSize);
  59.  
  60.     printf("\t%d (Corresponding Number of Categories)\n",
  61.     SerialData->NumCategories);
  62.  
  63.     /* ------------------------ */
  64.     /* Request Cell Expectation    */
  65.     /* ------------------------ */
  66.     GetInt(NEED_CELL_EXPECT(MIN_CELL_XPCT, MAX_CELL_XPCT), &UserIntEntry);
  67.  
  68.     REPORT_USER_INT_ENTRY(UserIntEntry, "Minimum Cell Expectation");
  69.  
  70.     /* ---------------------- */
  71.     /* Clamp Cell Expectation */
  72.     /* ---------------------- */
  73.     SerialData->UserCellExpect =
  74.     __min(MAX_CELL_XPCT, __max(MIN_CELL_XPCT, UserIntEntry));
  75.  
  76.     SHOW_INT_VALUE_USED(UserIntEntry, SerialData->UserCellExpect);
  77.  
  78.     fflush(NULL);fprintf(stderr, "%c", NewlineCh);
  79.     /* ------------------------------------------ */
  80.     /* Calculate Minimum Number of Pairs Required */
  81.     /* ------------------------------------------ */
  82.     SerialData->MinNumPairs =
  83.     (long)SerialData->NumCategories *
  84.     (long)SerialData->UserCellExpect;
  85.  
  86.     /* ------------------------------------------ */
  87.     /* Get Number of Serial Pairs to be Generated */
  88.     /* ------------------------------------------ */
  89.     {
  90.     char    Prompt[64];
  91.  
  92.     sprintf(Prompt, "How Many Pairs Are To Be Generated?"
  93.             "  [%ld ...]: ", SerialData->MinNumPairs);
  94.  
  95.     GetLong(Prompt, &UserLongEntry);
  96.     }
  97.  
  98.     REPORT_USER_INT_ENTRY(UserLongEntry,
  99.     "Number of Serial Pairs To Be Generated");
  100.  
  101.     SerialData->UserNumPairs =
  102.     __max(UserLongEntry, SerialData->MinNumPairs);
  103.  
  104.     SHOW_INT_VALUE_USED(UserLongEntry, SerialData->UserNumPairs);
  105.  
  106.     fflush(NULL);fprintf(stderr, "%c", NewlineCh);
  107.  
  108.     SerialData->CallStatusOK = TRUE;
  109. }
  110.